package com.wpre.booksystem.mapper;

import com.wpre.booksystem.model.BookInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-11-12
 * Time: 21:51
 */
@Mapper
public interface BookMapper {

    /**
     * 添加图书
     *
     * @param bookInfo
     * @return
     */
    @Insert("insert into book_info(book_name,author,count,price,`status`,publish) " +
            "values (#{bookName},#{author},#{count},#{price},#{status},#{publish})")
    Integer insertBook(BookInfo bookInfo);

    //统计数据库中图书的总记录数
    @Select("select count(1) from book_info where status != 0")
    Integer count();

    //查询图书(翻页功能)
    @Select("select * from book_info where status !=0 order by id limit #{offset},#{limit}")
    List<BookInfo> queryBookByPage(Integer offset,Integer limit);

    @Select("select * from book_info where id = #{bookId}")
    BookInfo queryBookById(Integer bookId);


    //更新图书
    Integer updateBook(BookInfo bookInfo);

    //批量删除
    void batchDelete(List<Integer> ids);
}
